#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <sys/stat.h>

#include <unistd.h>


	
static int executionFailure(char *context)
{
        fprintf(stderr, "su: %s. Error:%s\n", context, strerror(errno));
        return -errno;
}
static int permissionDenied()
{
        // the superuser activity couldn't be started
        printf("su: permission denied\n");
        return 1;
}

int main(int argc, char* argv[]){
		struct stat stats;
        struct passwd *pw;
        int uid = 0;
        int gid = 0;
		
		if(setgid(gid) || setuid(uid)) 
                return permissionDenied();

        char *exec_args[argc + 1];
        exec_args[argc] = NULL;
        exec_args[0] = "sh";
        int i;
		char stra[256];
		sprintf(stra,"%d",argc);
		char coma[80];
				strcpy(coma,"main cmd num : ");
				strcat(coma,stra);
				puts(coma);
        for (i = 1; i < argc; i++)
        {
                exec_args[i] = argv[i];
				char Com[80];
				strcpy(Com,"main cmd: ");
				strcat(Com,exec_args[i]);
				puts(Com);

        }
        execv("/system/bin/sh", exec_args);
        return executionFailure("sh");

}
	
	
